﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

using Gurucore.Framework.Core.Proxy;
using Gurucore.Framework.DataAccess;

namespace Gurucore.Framework.Business.TransactionContext
{
	public class AfterSuccessInterceptor : InterceptorBase
	{
		public override object Intercept(object p_oInstance, MethodInfo p_oMethod, InterceptorType p_eInterceptorType, params object[] p_arrArg)
		{
			DataAccessContext oDACtx = DataAccessContext.GetDataAccessContext();

			object[] arrTransAttr = p_oMethod.GetCustomAttributes(typeof(TransactionBoundAttribute), true);
			if (arrTransAttr.Length > 0)
			{
				//Console.WriteLine("Commit Transaction");
				oDACtx.LeaveTransaction(true);
			}

			return 0;
		}
	}
}
